package cc.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

/**
 * @ClassName: UserServlet
 * @Description: 用户的servlet
 * @Author: 晓东√
 * @Date: 2024-09-03 08:56
 * @Version: 1.0
 **/
@WebServlet("/user.action")
public class UserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");

        //业务
        //接收前端参数
        String userName = req.getParameter("userName");
        String userPhone = req.getParameter("userPhone");

        String[] hobbies = req.getParameterValues("hobby");

        System.out.println(userName+"--------"+userPhone+"-------");

        Arrays.stream(hobbies).forEach(h-> System.out.println(h));

    }
}
